﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       Logon
 * 类型：       登录画面
 * 功能说明：   登录
 * 作者：       谈震鸣
 * 创建日期：   2007/08/14
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
 */
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System.Auth.Dao;
using Shpm.System;
using Shpm.App.Commons.Db.Beans.Inp;
using Shpm.App.Input.Dao;

public partial class Logon : System.Web.UI.Page
{
    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    #endregion

    #region 退出按钮
    protected void btnExit_Click(object sender, EventArgs e)
    {
        
    }
    #endregion

    #region 登录按钮
    /*
     *名称： btnLogon_Click
     *功能： 左击登录按钮
     *参数： 无
     *返回： 无
     *说明： 验证用户名密码
     */
    protected void btnLogon_Click(object sender, EventArgs e)
    {
        lblErr.Text = string.Empty;
        if (ComValidator1.DoValidator() && ComValidator2.DoValidator())
        {
            MstSysUserBean dataBean = new MstSysUserBean();
            dataBean.SysUserId = txtSysUserId.Text;
            dataBean.PassWd = txtPassWD.Text;
            MstGroupBean dataGroupBean = new MstGroupBean();
            dataGroupBean.SysUserId = txtSysUserId.Text;
            LogonDao Dao = new LogonDao();
            dataBean = Dao.Load(dataBean);
            if (dataBean != null)
            {
                // 设置登录用户及权限组信息
                SysUserBean sysUserBean = new SysUserBean();
                sysUserBean.setMstSysUserBean(dataBean);
                sysUserBean.setGroups(Dao.FindByUserGroup(dataGroupBean));

                // 设置登录用户的部门信息
                sysUserBean.setDepartments(Dao.FindDepartByMstSysUser(dataBean));

                // 设置登录用户的员工信息
                MstEmployeeBean empBean = new MstEmployeeBean();
                empBean.EmployeeId = dataBean.EmployeeId;
                empBean = Dao.Load(empBean);
                MstEmployeeBean meBean = new MstEmployeeBean();
                meBean.EmployeeId = empBean.EmployeeId;
                HealthAssignDao dao = new HealthAssignDao();
                IList dataList = dao.FindByEmployee(meBean);
                if (dataList.Count > 0)
                {
                    meBean = (MstEmployeeBean)dataList[0];
                    if (meBean.JobLimit != null)
                    {
                        empBean.JobLimit = meBean.JobLimit;
                    }
                    else
                    {
                        empBean.JobLimit = "0";
                    }
                }
                sysUserBean.setEmployeeBean(empBean);
                Context.Session[Constants.USER_CONTEXT_KEY] = sysUserBean;
                string newUrl = "~/App/System/FrameMainForm.aspx";
                Response.Redirect(newUrl);
            }
            else
            {
                string str = HttpContext.GetGlobalResourceObject("Message", "Logon_Err") as string;
                lblErr.Text = str;
                Session.Remove(Constants.USER_CONTEXT_KEY);
            }
        }
        else
        {
            if( ComValidator1.DoValidator()==false )
                lblErr.Text = ComValidator1.ErrorMessage;
            else
                lblErr.Text = ComValidator2.ErrorMessage;
        }
    }
    #endregion
}
